package Others.DesignPattern.VisitorPattern.Pattern;

import Others.DesignPattern.VisitorPattern.Pattern.human.man;
import Others.DesignPattern.VisitorPattern.Pattern.human.people;
import Others.DesignPattern.VisitorPattern.Pattern.human.woman;
import Others.DesignPattern.VisitorPattern.Pattern.status.*;

import java.util.ArrayList;
import java.util.List;

public class main {
    public static void main(String[] args) {
        //访问者模式

        ObjectStructure OS = new ObjectStructure();
        man man = new man();
        woman woman = new woman();

        OS.Attach(man);
        OS.Attach(woman);

        success success = new success();
        OS.Display(success);

        failing failing = new failing();
        OS.Display(failing);

        amativeness amativeness = new amativeness();
        OS.Display(amativeness);

        // 说说好处吧，这个时候如果在想要添加一些新的状态，
        // 只需要去添加对应的Action实现类即可，而不再需要去改动其他的代码

        //如 后续加了一个结婚的状态
        marriage marriage = new marriage();
        OS.Display(marriage);


    }

    private static class ObjectStructure{
        List<people> elements = new ArrayList<>();

        public void Attach(people element){
            elements.add(element);
        }

        public void Detach(people element){
            elements.remove(element);
        }

        public void Display(Action action){
            for(people element : elements){
                element.accept(action);
            }
        }

    }

}
